<?php
require_once "PHPUnit/Extensions/Database/TestCase.php";
require_once '../orders.php';

class DbTest extends PHPUnit_Extensions_Database_TestCase {
    public function getConnection() {
        $pdo = new PDO('mysql:host=localhost;dbname=fyptwo', "root", "");
        return $this->createDefaultDBConnection($pdo);
    }
    
    public function getDataSet() {
        return $this->createFlatXMLDataSet('../xml/orders.xml');
    }
        
    public function testGetStockID(){
        $conn = dbConnect();
        $sid = getStockID($conn, 'Microsoft');
        $this->assertEquals(1, $sid);
    }
    
    public function testCreateOrder(){
        $dt = getCurrentDateTime();
        $conn = dbConnect();
        createOrder($conn, 1, 1, 500, 4.0, $dt, 'sell');
        $actual = $this->getConnection()->getRowCount('order');
        $this->assertEquals(2, $actual);
    }

    public function testValidateBuyPriceFail(){
        //a player trying to buy a stock, but their money is insufficient
        $conn = dbConnect();
        $valid = validateBuyOrder($conn, 100000, 5000, 1);
        $this->assertEquals(False, $valid);
    }

    public function testValidateBuyPricePass(){
        //a player trying to buy a stock, and their money is just nice same with the total price they need to pay
        $conn = dbConnect();
        $valid = validateBuyOrder($conn, 1000, 500, 1);
        $this->assertEquals(True, $valid);
    }

    public function testValidateSellPriceFail(){
        //a player want to sell 2000 shares, but he/she only have 1000 shares
        $conn = dbConnect();
        $valid = validateSellOrder($conn, 2000, 1, 1);
        $this->assertEquals(False, $valid);
    }

    public function testValidateSellPricePass(){
        //a player want to sell 500 shares, and he/she have 1000 shares
        $conn = dbConnect();
        $valid = validateSellOrder($conn, 500, 1, 1);
        $this->assertEquals(True, $valid);
    }
    
//    public function testResolveOrders(){
//        //no seller nor buyer
//    }
//
//    public function testResolveOrders(){
//        //no seller, has buyer
//    }
//
//    public function testResolveOrders(){
//        //no buyer, has seller
//    }
//
//    public function testResolveOrders(){
//        //has sellers, has buyers, with same quantity and seller > buyer
//    }
//
//    public function testResolveOrders(){
//        //has sellers, has buyers, with same quantity and seller < buyer
//    }
//
//    public function testResolveOrders(){
//        //has 2 sellers at different price, has 1 buyer, with same quantity and seller < buyer, which seller come first?
//    }
//
//    public function testResolveOrders(){
//        //has 2 sellers at different price, has 1 buyer, with different quantity and seller < buyer, which seller come first? quantity?
//    }
//
//    public function testResolveOrders(){
//        //has 2 buyers at different price, has 1 seller, with different quantity and seller < buyer, which buyer come first? quantity?
//    }
//
//    public function testResolveOrders(){
//        //has 2 sellers same bid price, has 1 buyer, with 1 seller has same quantity as 1 buyer, which seller left?
//    }
//
//    public function testResolveOrders(){
//        //has 2 sellers same bid price, has 1 buyer, buyer need 1000 --> Seller 1 sell 500 --> seller 2 sell 1500
//    }
//
//    public function testResolveOrders(){
//        //has 2 buyers same bid price, has 1 seller, with 1 seller has same quantity as 1 buyer, which buyer get first?
//    }
//
//    public function testResolveOrders(){
//        //has 2 buyers same bid price, has 1 seller: buyer 1 need 500 --> buyer 2 need 1000 --> seller has 700
//    }
//
//    public function testCancelOrder(){
//
//    }
    
}

?>
